// Source File Name:   EDImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BIN;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.BN;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.ED;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.LIST_BN;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TEL;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.Iterator;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BINImpl, BLImpl, CSImpl, 
//            NullFlavorImpl, STImpl, TELImpl, TYPEImpl

public class EDImpl extends ANYImpl
    implements ED
{

    public static final String RCS_ID = "$Header: EDImpl.java 1.0 2006/09/16 09:23:55 amchanda noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: EDImpl.java 1.0 2006/09/16 09:23:55 amchanda noship $", "com.sunwayhorizo.health.hl7.datatypes.common");
    protected String _data;
    protected CS _mediaType;
    protected CS _charset;
    protected CS _language;
    protected CS _compression;
    protected TEL _reference;
    protected BIN _integrityCheck;
    protected CS _integrityCheckAlgorithm;
    protected ED _thumbnail;
    protected CS _representation;
    private static final String INTEGRITY_CHECK_ALGORITHM = "integrityCheckAlgorithm";
    private static final String INTEGRITY_CHECK = "integrityCheck";
    private static final String COMPRESSION = "compression";
    private static final String MEDIA_TYPE = "mediaType";
    private static final String REFERENCE = "reference";
    private static final String THUMBNAIL = "thumbnail";
    private static final String LANGUAGE = "language";
    private static final String CHARSET = "charSet";
    private static final String REPRESENTATION = "representation";
    private static final ED nullNI = new EDImpl(CSImpl.valueOf("NI"));
    private static final ED nullOTH = new EDImpl(CSImpl.valueOf("OTH"));
    private static final ED nullNINF = new EDImpl(CSImpl.valueOf("NINF"));
    private static final ED nullPINF = new EDImpl(CSImpl.valueOf("PINF"));
    private static final ED nullUNK = new EDImpl(CSImpl.valueOf("UNK"));
    private static final ED nullASKU = new EDImpl(CSImpl.valueOf("ASKU"));
    private static final ED nullNAV = new EDImpl(CSImpl.valueOf("NAV"));
    private static final ED nullMSK = new EDImpl(CSImpl.valueOf("MSK"));
    private static final ED nullNA = new EDImpl(CSImpl.valueOf("NA"));
    private static final ED nullNASK = new EDImpl(CSImpl.valueOf("NASK"));

    public static ED valueOf(String s, CS cs, CS cs1, CS cs2, CS cs3, TEL tel, BIN bin, CS cs4, 
            ED ed, CS cs5)
    {
        return new EDImpl(s, cs, cs1, cs2, cs3, tel, bin, cs4, ed, cs5);
    }
    
    
    protected EDImpl(CS cs)
    {
        super(true, cs);
       // _data = null;
    }

    protected EDImpl(String s, CS cs, CS cs1, CS cs2, CS cs3, TEL tel, BIN bin, 
            CS cs4, ED ed, CS cs5)
    {
        if(s == null && tel == null)
            throw ANYImpl.newNullException("ED", "constructor", "reference");
        if(cs == null || cs.isNull().isTrue())
        {
            throw ANYImpl.newNullException("ED", "constructor", "mediaType");
        } else
        {
            _data = s;
            _mediaType = cs;
            _charset = cs1;
            _language = cs2;
            _compression = cs3;
            _reference = tel;
            _integrityCheck = bin;
            _integrityCheckAlgorithm = cs4;
            _thumbnail = ed;
            _representation = cs5;
            return;
        }
    }

    public CS charset()
    {
        if(isNull().isTrue())
            return CSImpl.nullCS(NullFlavorImpl.NI);
        else
            return _charset;
    }

    public CS compression()
    {
        if(isNull().isTrue())
            return CSImpl.nullCS(NullFlavorImpl.NI);
        else
            return _compression;
    }

    public CS representation()
    {
        if(isNull().isTrue())
            return CSImpl.nullCS(NullFlavorImpl.NI);
        else
            return _representation;
    }

    public ST literal()
    {
        ST st = null;
        if(isNull().isTrue())
            st = STImpl.nullST(NullFlavorImpl.NI);
        if(_data == null)
        {
            _data = "";
            st = STImpl.valueOf(_data);
        } else
        {
            st = STImpl.valueOf(_data);
        }
        return st;
    }

    public BIN integrityCheck()
    {
        if(isNull().isTrue())
            return BINImpl.nullBIN(null);
        else
            return _integrityCheck;
    }

    public CS integrityCheckAlgorithm()
    {
        if(isNull().isTrue())
            return CSImpl.nullCS(NullFlavorImpl.NI);
        else
            return _integrityCheckAlgorithm;
    }

    public CS language()
    {
        if(isNull().isTrue())
            return CSImpl.nullCS(NullFlavorImpl.NI);
        else
            return _language;
    }

    public CS mediaType()
    {
        if(isNull().isTrue())
            return CSImpl.nullCS(NullFlavorImpl.NI);
        else
            return _mediaType;
    }

    public TEL reference()
    {
        if(isNull().isTrue())
            return TELImpl.nullTEL(NullFlavorImpl.NI);
        else
            return _reference;
    }

    public ED thumbnail()
    {
        if(isNull().isTrue())
            return nullED(NullFlavorImpl.NI);
        else
            return _thumbnail;
    }

    public BL contains(BN bn)
    {
        throw ANYImpl.newUnsupportedException("ED", "contains");
    }

    public BN head()
    {
        throw ANYImpl.newUnsupportedException("ED", "head");
    }

    public BL isEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.TRUE;
        else
            return BLImpl.FALSE;
    }

    public BN item(INT int1)
    {
        throw ANYImpl.newUnsupportedException("ED", "item");
    }

    public INT length()
    {
        throw ANYImpl.newUnsupportedException("ED", "length");
    }

    public Iterator listIterator()
    {
        throw ANYImpl.newUnsupportedException("ED", "listIterator");
    }

    public BL notEmpty()
    {
        if(!isNull().booleanValue())
            return BLImpl.TRUE;
        else
            return BLImpl.FALSE;
    }

    public LIST_BN tail()
    {
        throw ANYImpl.newUnsupportedException("ED", "tail");
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.ED;
    }

    public BL equal(ANY any)
    {
        if(any == null || isNull().or(any.isNull()).isTrue())
            return BLImpl.FALSE;
        if(any.dataType().equal(com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.ED).isFalse())
            return BLImpl.FALSE;
        ED ed = (ED)any;
        if(ed.mediaType().equal(_mediaType).isFalse())
            return BLImpl.FALSE;
        if(ed.stringValue() != null && _data != null)
            if(ed.compression().equal(_compression).or(ed.compression().isNull().and(_compression.isNull())).and(ed.representation().equal(_representation).or(ed.representation().isNull().and(_representation.isNull()))).isTrue())
                return BLImpl.valueOf(_data.equals(ed.stringValue()));
            else
                return BLImpl.nullBL(NullFlavorImpl.UNK);
        if(ed.reference().equal(_reference).isTrue())
            return BLImpl.TRUE;
        else
            return BLImpl.nullBL(NullFlavorImpl.UNK);
    }

    public int hashCode()
    {
        int i = 17;
        if(isNull().isFalse())
        {
            i = i * 37 + _mediaType.hashCode();
            if(_data == null)
                i = i * 37 + _reference.hashCode();
            else
                i = i * 37 + _data.hashCode();
        }
        return i;
    }

    public String stringValue()
    {
        return _data;
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLElement xmlelement = (XMLElement)xmldocument.createElement(s);
//            if(mediaType() != null && !mediaType().isNull().isTrue())
//                xmlelement.setAttribute("mediaType", mediaType().code().stringValue());
//            if(compression() != null && !compression().isNull().isTrue())
//                xmlelement.setAttribute("compression", compression().code().stringValue());
//            if(integrityCheck() != null && !integrityCheck().isNull().isTrue())
//                xmlelement.setAttribute("integrityCheck", integrityCheck().stringValue());
//            if(integrityCheckAlgorithm() != null && !integrityCheckAlgorithm().isNull().isTrue())
//                xmlelement.setAttribute("integrityCheckAlgorithm", integrityCheckAlgorithm().code().stringValue());
//            xmlelement.setAttribute("encoding", "TXT");
//            String s1 = stringValue();
//            if(s1 != null)
//            {
//                org.w3c.dom.Text text = xmldocument.createTextNode(s1);
//                xmlelement.appendChild(text);
//            }
//            if(reference() != null && !reference().isNull().isTrue())
//                xmlelement.appendChild(((TELImpl)reference()).writeXML(xmldocument, "reference")[0]);
//            if(thumbnail() != null && !thumbnail().isNull().isTrue())
//                xmlelement.appendChild(((EDImpl)thumbnail()).writeXML(xmldocument, "translation")[0]);
//            return (new XMLNode[] {
//                xmlelement
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

    public static ED nullED(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

	public byte[] byteArray() {
	
		return null;
	}

}
